﻿using System;

namespace space1
{
    class Program
{
    // 判断一个数是否是素数
    static bool IsPrime(int number)
    {
        if (number <= 1)
            return false;
        if (number == 2)
            return true;
        if (number % 2 == 0)
            return false;
        int boundary = (int)Math.Floor(Math.Sqrt(number));
        for (int i = 3; i <= boundary; i += 2)
        {
            if (number % i == 0)
                return false;
        }
        return true;
    }

    // 输出所有素数因子
    static void PrimeFactors(int number)
    {
        Console.Write($"数字 {number} 的所有素数因子为：");
        for (int i = 2; i <= number; i++)
        {
            if (number % i == 0 && IsPrime(i))
            {
                Console.Write(i + " ");
            }
        }
        Console.WriteLine();
    }

    static void Main()
    {
        Console.WriteLine("请输入一个正整数：");
        if (int.TryParse(Console.ReadLine(), out int userInput) && userInput > 0)
        {
            PrimeFactors(userInput);
        }
        else
        {
            Console.WriteLine("请输入有效的正整数。");
        }
    }
}
}

